<!DOCTYPE html>
<html lang="zh-cmn-Hans">
  <head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" href="../../../../../../static/mobile/default/css/layout.css?v=2"/>
    <link rel="icon" type="image/png" href="../../../../../../static/favicon.ico"/>
        <script src="../../../../../../static/js/jquery/jquery/2.1.4/jquery.min.js"></script>
        <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <script src="../../../../../../static/js/jquery/jquery.cookie.js"></script>
    <script src="../../../../../../static/mobile/default/js/page.js?v=1"></script>
    <title>资金明细详情  - 达漂亮</title>
          
<link rel="stylesheet" href="../../../../../../static/mobile/default/css/orderDetails.css" />


</head>
<body >
  <div class="page orderDetails">
    		<div class="page-hd">
            <div class="header base-header bor-1px-b">
                <div class="header-left">
                    <a href="javascript:history.go(-1)" class="left-arrow"></a>
                </div>
                <div class="header-title">资金明细详情</div>
                <div class="header-right">
                    <!-- <a href=""></a> -->
                </div>
            </div>
        </div>
      
<div class="page-bd">
    <!-- 页面内容-->
    
   <script type="text/html" id="orderDetailTpl">
     {{if orderInfo.order_status ==0}}
   <div class="top">
        <div><img src="/static/mobile/default/images/orderIcon03.png" alt="">
            <span class="fs34 fw_b color_w">待付款</span></div>
                      <!-- <div class="time"><p class="fs26">剩 <em class="color_w">22时59分12秒</em> 自动关闭</p></div>-->
                </div>
    {{/if}}
    <div class="address">
        <div class="fs30 fw_b color_3">{{orderInfo.consignee}}</div>
        <p class="fs28 color_9 color_9" >{{orderInfo.full_region}} {{orderInfo.address}}</p>
    </div>
    <div class="orderBox">
        <div class="code fs28"><p class="color_3">订单编号:{{orderInfo.order_sn}}</p><span class="color_9 ">{{orderInfo.order_status_text}}</span>
        </div>
        <div class="goodslist">
        {{each orderGoods as item,index}}
                        <a href="../../../goods/info/id/goodInfo.html?goodsId={{item.goods_id}}" class="goods">
                <img src="{{item.list_pic_url}}" alt="">
                <div class="goodsinfo">
                    <p class="fs28 color_3">{{item.goods_name}}</p>
                    <div class="appleBox"><span class="fs28 color_9"></span>
                                            </div>
                                            <div class="money">
                            <div>
                                <div class="color_3 fs24 num mg_rg"><p class="fw_b fm_p">￥</p><em class="fs36">{{item.retail_price}}</div>
                                                            </div>
                        <em class="fs28 color_3">x{{item.number}}</em></div>
                                    </div>
            </a>
            {{/each}}
                    </div>

        <div class="cell">
            <span class="fs28 color_3 fw_b">实付金额</span>
            <div class="color_3 fs30 num"><p class="fw_b fm_p">￥</p><em class="fs40">{{orderInfo.actual_price}}</em>
            </div>
        </div>
    </div>
    
    
    <div class="payInfo fs28 color_9">
            {{if orderInfo.pay_id}}
                <span>支付方式 : 微信支付</span>
            {{else }}
                <span>支付方式 : 余额支付</span>
            {{/if}}
            
            <span>下单时间 : {{orderInfo.add_time}}</span>
            <span>支付时间 : {{orderInfo.pay_time}}</span>
            <span>发货时间 : {{orderInfo.shipping_time}}</span>
            <span>确认收货时间 : {{orderInfo.confirm_time}}</span>
    </div> 
    {{if orderInfo.order_status ==0}}
     <div class="button">

                <span  class="fs28 fw_b color_r bor" onclick='choosePay($(this))' data-order_id="{{orderInfo.id}}" data-orderMoney="{{orderInfo.actual_price}}">立即支付</span>
            </div>
            {{/if}}
             {{if orderInfo.order_status ==3}}
     <div class="button">
        
                <span  class="fs28 fw_b color_r bor confirmReceipt">确认收货</span>
            </div>
            {{/if}}
    </script>
    
   
</div>

  </div>

<script src="../../../../static/js/art-template.js"></script>
<script src="../../../../static/mobile/default/js/lib/fastclick.js"></script>
<script src="../../../../static/js/jquery/lazyload/jquery.lazyload.js"></script>


<script type="text/javascript">
var order_id = getUrlParam('moneylogId')

      share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
$(function(){
    
     getOrderDetail(order_id)
    //根据订单id获取订单详情
    	function getOrderDetail(order_id){
        jq_ajax('https://mp.jianguoes.com/api/mp/detailOrder',{orderId:order_id},function(res){
            if(res.errno  != 0 ){
                _alert(res.errmsg);
                return false;
            }
            $('.page-bd').append(template('orderDetailTpl',res.data))
             var array  = Array.prototype.slice.apply($('.goods'));
                                    if(getUrlParam('PID')==$.cookie('myID')){
                                        for (var i = 0; i < array.length; i++) {
                                        
                                        var url = $('.goods').eq(i).attr('href')
                                        $('.goods').eq(i).attr('href',url)
                                    }
                                    }else{
                                        for (var i = 0; i < array.length; i++) {
                                        
                                        var url = $('.goods').eq(i).attr('href').split('&P')[0]
                                        $('.goods').eq(i).attr('href',url+'&PID='+$.cookie('myID'))
                                    }
                                    }
            
        },'get')	
	}
    $('.left-arrow').on('click',function(){
        window.location.href = '/shop/order/index.html';
    })
    //订单操作
    $('.button').on('click','span',function(res){
        var _this = $(this);
        var arr = new Object();
        arr.order_id = '565';
        arr.type = _this.data('type');
		if (arr.type == 'cancel'){
			_alert('确定取消此订单？',function(){action(arr)});
			return false;
		}else if(arr.type == 'refund'){
            _alert('确定申请取消订单？',function(){
                arr.type = 'cancel';
                action(arr)
            });
            return false;
        }
		return action(arr);
    })
	function action(arr){
        jq_ajax('/shop/api.order/action.html',arr,function(res){
            if(res.code  == 0 ){
                _alert(res.errmsg);
                return false;
            }
            window.location.reload();
        })	
	}
	$('.confirmReceipt').click(function(){
	    jq_ajax('https://mp.jianguoes.com/api/mp/confirmOrder',{orderId:order_id},function(res){
            if(res.errno  != 0 ){
                _alert(res.errmsg);
                return false;
            }
            $('.page-bd').append(template('orderDetailTpl',res.data))
            
        },'get')
	})
})
</script>

  <div class="alertBox">
      <div class="alertBG"></div>
      <div class="alert">
          <div class="text fs30 color_3 bor_b">

          </div>
          <!-- 单按钮 -->
          <div class="button fs32 fw_b color_r">
              知道了
          </div>
          <!-- 双按钮 -->
          <div class="buttonBox fs32 fw_b">
              <span class="color_9 bor_r cancel">取消</span>
              <span class="color_r confirm">确定</span>
          </div>
      </div>
  </div>
  <script type="text/javascript">
      var is_xcx = 0;
      $(document).on('click', 'a', function () {
          var href = $(this).attr('href');
          if (href.indexOf('/pages') != -1) {
              if (is_xcx == 1) {
                  wx.miniProgram.navigateTo({
                      url: href
                  })
                  return false;
              } else {
                  return false;
              }
          }
      })
  </script>
          <script type="text/html" id="payListTpl">
    <div class="block">
        <label for="other" style="width: 100%;">
            <div class="payType">
                <img src="../../../../static/mobile/default/images/balancePay.png" alt="">
                <div>
                    <span class="fs30 color_3">余额支付</span>
                    <span class="fs26 color_r">(￥{{mlsuser.allProfit}})</span>
                </div>
            </div>
        </label>
        <label for="other">
            <div class="iconBox">
                <input type="radio" class="check" name="pay_id" value="other" id="other">
                <i class="icon_checked"></i>
            </div>
        </label>
    </div>
    <div class="block">
        <label for="wxpay" style="width: 100%;">
            <div class="payType">
                <img src="../../../../static/mobile/default/images/weixinPay.png" alt="">
                <div>
                    <span class="fs30 color_3">微信支付</span>
                </div>
            </div>
        </label>
        <label for="wxpay">
            <div class="iconBox">
                <input type="radio" class="check" name="pay_id" value="wxpay" id="wxpay">
                <i class="icon_checked"></i>
            </div>
        </label>
    </div>
</script>
  <!-- 支付方式 -->
  <div class="payment">
        <div class="model payModel">
            <div class="modelContent">
                <div class="closeBox"><img src="../../../../static/mobile/default/images/close_icon.png" alt=""></div>
                <div class="title fs36 color_3 fw_b">请选择支付方式</div>
                <div class="cantre pay" id="payListBox">

                    <p class="get_list_tip">加载中...</p>

                </div>
                <div class="buttBox">
                    <span class="fs32 fw_b color_w BGcolor_r payConfirm">确认支付</span>
                </div>
            </div>
        </div>
</div>
         <link rel="stylesheet" href="../../../../static/mobile/default/css/payment.css" />
        <link rel="stylesheet" href="../../../../static/mobile/default/css/userData.css" />
        <script type="text/javascript">
        
        
        //选择支付方式
        var totalGoodsPrice = ''
        function choosePay(that){
            totalGoodsPrice = that.attr('data-orderMoney')
             jq_ajax('https://mp.jianguoes.com/api/mp/getUserInfo', '', function (res) {
                    if (res.errno != 0) {
                        _alert(res.errmsg);
                        return false;
                    }
                    $('#payListBox').html(template('payListTpl', res.data));
                    $('.payModel').show();
                }, 'get');
               
        }
        
        $('.closeBox').on('click', function () {
                $('.model').hide();
            });
            
             //下单
            $('.buttBox .payConfirm').on('click', function (event) {
                
                var pay_id = $("input[name='pay_id']:checked").val();
                if (typeof (pay_id) == 'undefined' || pay_id < 1) {
                    _alert('请选择支付方式.');
                    return false;
                }

                    if(pay_id == 'other'){
                     jq_ajax('https://mp.jianguoes.com/api/mp/amountpay', {orderId:order_id}, function (res) {
                        if (res.errno != 0) {
                            _alert(res.errmsg);
                            return false;
                        }
                        
                         //支付成功跳转到支付成功页面,并不是真正到账
                        window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/paysuccess.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
                    }, 'get')
                }else{
                     jq_ajax('https://mp.jianguoes.com/api/mp/prepay', {orderId:order_id}, function (res) {
                        if (res.errno != 0) {
                            _alert(res.errmsg);
                            return false;
                        }
                        console.log(res);
                        onBridgeReady(res.data,order_id)
                        // window.location.href = '/shop/flow/done/order_id/done.html';
                    }, 'get')
                }
                
            event.stopPropagation()
            })
            
            
            
            function onBridgeReady(params,order_id) {
                console.log(params);
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', {
                    "appId": params.appId,     //公众号名称，由商户传入     
                    "timeStamp": params.timeStamp,         //时间戳，自1970年以来的秒数     
                    "nonceStr": params.nonceStr, //随机串     
                    "package": params.package,
                    "signType": params.signType,         //微信签名方式：     
                    "paySign": params.paySign //微信签名 
                },
                    function (res) {
                        var last = JSON.stringify(res); //将JSON对象转化为JSON字符
                        if(res.err_msg === "get_brand_wcpay_request:ok" ) {
                            //支付成功跳转到支付成功页面,并不是真正到账
                            window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/paysuccess.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
                        }
                        if (res.err_msg === "get_brand_wcpay_request:cancel") {
                            //交易取消时需要更新账户和充值记录
                             window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/payfail.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
                        }
                        if (res.err_msg === "get_brand_wcpay_request:fail") {
                            //交易取消时需要更新账户和充值记录
                                window.location.href = "https://mp.jianguoes.com/shop/flow/done/order_id/payfail.html?orderId="+order_id+'&orderMoney='+totalGoodsPrice;
             }
                    });
            }
            // if (typeof WeixinJSBridge == "undefined") {
            //     if (document.addEventListener) {
            //         document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            //     } else if (document.attachEvent) {
            //         document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            //         document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            //     }
            // } else {
            //     onBridgeReady();
            // }

        </script>
    </body>
</html>